//此模块支持浏览器环境和nodejs
!(function(global) {
	function inherit (subClass,baseClass) {
		subClass.prototype = Object.create(baseClass.prototype);
		subClass.prototype.constructor = subClass;
	}
	
	function DetectorBase(configs) {
		if(!this instanceof DetectorBase) {
			throw new Error("Do not invoke with new");
		}
		this.configs = configs;
		this.analyze();
	}

	DetectorBase.prototype.detect = function() {
		throw new Error("Not implemented");
	}

	DetectorBase.prototype.analyze = function() {
		console.log("analyzing...");
		this.data = "###data###";
	}

	function LinkDetector(links) {
		DetectorBase.apply(this,arguments);
		if(!this instanceof LinkDetector) {
			throw new Error("Do not invoke with new");
		}
		this.links = links;
	}

	function ContainerDetector(containers) {
		DetectorBase.apply(this,arguments);
		if(!this instanceof ContainerDetector) {
			throw new Error("Do not invoke with new");
		}
		this.containers =containers;
	}
	inherit(LinkDetector,DetectorBase);
	inherit(ContainerDetector,DetectorBase);
	
	LinkDetector.prototype.detect=function () {
		console.log("Loading Data:"+ this.data);
		console.log("link detector started");
		console.log("Scaning links:"+this.links);
	}
	
	ContainerDetector.prototype.detect=function () {
		console.log("Loading Data:"+ this.data);
		console.log("container detector started");
		console.log("Scaning containers:"+this.containers);
	}
	
	//阻止属性被修改
	Object.freeze(DetectorBase);
	Object.freeze(DetectorBase.prototype);
	Object.freeze(LinkDetector);
	Object.freeze(LinkDetector.prototype);
	Object.freeze(ContainerDetector);
	Object.freeze(ContainerDetector.prototype);
	//抛出给全局对象
	Object.defineProperties(global,{
		LinkDetector:{value:LinkDetector},
		ContainerDetector:{value:ContainerDetector},
		DetectorBase:{value:DetectorBase},
	})
})(this);